package com.demo.myapplication.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.demo.myapplication.R;
import com.demo.myapplication.utils.CommonUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SingleInstanceAffinityActivity extends AppCompatActivity {
  public static String EXTRA_LAUNCH_MODE = "launch_mode";
  @BindView(R.id.tv_launch_mode)
  TextView tvLaunchMode;

  CommonUtils.LAUNCH_MODE launchMode;

  @Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_single_instance);
    ButterKnife.bind(this);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    initIntent();
  }

  private void initIntent() {
    launchMode = (CommonUtils.LAUNCH_MODE) getIntent().getSerializableExtra(EXTRA_LAUNCH_MODE);
    if (launchMode == null) {
      tvLaunchMode.setText(getString(R.string.activity_launch_mode) + ":" + getString(R.string.standard));
      return;
    }
    switch (launchMode) {
      case SINGLE_INSTANCE:
        tvLaunchMode.setText(getString(R.string.activity_launch_mode) + ":" + getString(R.string.single_instance));
        break;
      case SINGLE_TASK:
        tvLaunchMode.setText(getString(R.string.activity_launch_mode) + ":" + getString(R.string.single_task));
        break;
      case SINGLE_TOP:
        tvLaunchMode.setText(getString(R.string.activity_launch_mode) + ":" + getString(R.string.single_top));
        break;
    }
  }

  @OnClick(R.id.btn_start_first)
  public void startFirst(View v) {
    startActivity(new Intent(this, FirstActivity.class));
  }

}
